<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll" />
    <label for="toggle-all"></label>
    <!-- 3.0键盘回车事件 
    3.1 输入框 - v-model获取值 绑定回车事件-->

    <input class="new-todo" placeholder="输入任务名称-回车确认" autofocus v-model="task" @keydown.enter="downFn" />
  </header>
</template>

<script>
export default {
  props: ["arr"],
  //3.2设置默认值
  data() {
    return {
      task: "",
    }
  },
  computed: {
    isAll: {
      set(checked) {
        this.arr.forEach((obj) => (obj.isDone = checked))
      },
      get(a) {
        console.log(a)
      },
    },
  },
  methods: {
    //3.3子传父当前任务加到list里
    downFn() {
      this.$emit("create", this.task)
      this.task = ""
    },
  },
}
</script>
